package com.shengyuan.manage_os.old.ying.erpm;

import org.json.JSONException;

import com.shengyuan.manage_os.R;
import com.shengyuan.manage_os.im.ECApplication;
import com.shengyuan.manage_os.old.ying.erpm.controls.PictureButton;
import com.shengyuan.manage_os.old.ying.erpm.controls.SourceSelectMenu;
import com.shengyuan.manage_os.old.ying.erpm.tasks.Submit_System_Setting_Data_Task;
import com.shengyuan.manage_os.old.ying.erpm.util.Utility;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

public class Actual_OA_CarBaoXiao extends BaseActivity {

	protected EditText editText_car_mingcheng,editText_car_jiayouliang, editText_car_jiayoufeiyong;
	private PictureButton PictureButton_car_jiayou,PictureButton_car_lichengbiao;
	

	@Override
	public void onClick(View view) {
		super.onClick(view);
	}
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.actual_oa_carbaoxiao);
		InitControls();
		if (!MainApplication.pShareUtil.ReadParam(editText_car_mingcheng.getId()+"").equals("")){
			editText_car_mingcheng.setText( MainApplication.pShareUtil.ReadParam(editText_car_mingcheng.getId()+""));
		}
	}
	@Override
	protected void SaveJsonData() {
		try {
			IsJson1 = true; mFinished = 1; mPrintenabled = 0;
			JsonMyID();
			getTask();
			getDataExt();
			
			getGPS();
			getCurrentUser();		
			getMemo();
			JsonPicture();
			save_pic();
			
		}catch (Exception e) {
		}
	}
	
	@Override
	protected void onResume() {
		super.onResume();
		if (PictureButton_car_jiayou!=null) {
			PictureButton_car_jiayou.postInvalidate();
		}
		if (PictureButton_car_lichengbiao!=null) {
			PictureButton_car_lichengbiao.postInvalidate();
		}
//		editText_car_mingcheng.setText( ECApplication.pShareUtil.ReadParam(editText_car_mingcheng.getId()+""));
	}
	private void save_pic() throws JSONException {
		if (PictureButton_car_jiayou!=null) {
			mJson.put( PictureButton_car_jiayou.FIELD+getString(R.string.title_actual_form_PictureButton), PictureButton_car_jiayou.mFileName);
		}		
		if (PictureButton_car_lichengbiao!=null) {
			mJson.put( PictureButton_car_lichengbiao.FIELD+getString(R.string.title_actual_form_PictureButton), PictureButton_car_lichengbiao.mFileName);
		}
	}
	
	@Override
	protected void SaveSelfPic(String sPath) {
		try {
			if (PictureButton_car_jiayou!=null) {
				CopyPicDest(PictureButton_car_jiayou, sPath);
			}			
			if (PictureButton_car_lichengbiao!=null) {
				CopyPicDest(PictureButton_car_lichengbiao, sPath);
			}
		} catch (Exception e) {
			Utility.MessageBox(this,e.getMessage());
		}
	}

	protected void getDataExt() throws JSONException {
		if (editText_car_mingcheng!=null) {
			mJson.put( getString(R.string.title_actual_form_editText_carmingcheng), editText_car_mingcheng.getText().toString());
			MainApplication.pShareUtil.WriteParam(editText_car_mingcheng.getId()+"", editText_car_mingcheng.getText().toString());
		}		
		if (editText_car_jiayouliang!=null) {
			mJson.put( getString(R.string.title_actual_form_editText_carjiayouliang), editText_car_jiayouliang.getText().toString());
		}	
		if (editText_car_jiayoufeiyong!=null) {
			mJson.put( getString(R.string.title_actual_form_editText_carjiayoufeiyong), editText_car_jiayoufeiyong.getText().toString());
		}
	}
//    @Override
//	public boolean onLongClick(View view) {
//    	super.onLongClick(view);
//    	String data;
//		switch (view.getId()) {
//		case R.id.editText_car_mingcheng:
//			Utility.HideEditFouce(editText_car_mingcheng);
//	        data = ECApplication.pShareUtil.ReadParam(Submit_System_Setting_Data_Task.T_ALLCHEPAI);
//			if (!data.equals("")) {
//				SourceSelectMenu menu = new SourceSelectMenu(editText_car_mingcheng);
//				menu.setArrays(data.split("\n"));
//				menu.show();
//				menu.setOnPopClickListener(new onPopClickListener());
//			}
//			break;
//		}
//		return true;
//    }

	@Override
	public void InitControls() {
		super.InitControls();
		editText_car_mingcheng = (EditText) findViewById(R.id.editText_car_mingcheng); 
		editText_car_jiayouliang = (EditText) findViewById(R.id.editText_car_jiayouliang);
		editText_car_jiayoufeiyong = (EditText) findViewById(R.id.editText_car_jiayoufeiyong);
		PictureButton_car_jiayou =(PictureButton)findViewById(R.id.PictureButton_car_jiayou);
		PictureButton_car_lichengbiao =(PictureButton)findViewById(R.id.PictureButton_car_lichengbiao);
//		editText_car_mingcheng.setOnLongClickListener(this);
	}
	@Override
	public Boolean IsPassed() {
		if (super.IsPassed()) {
			if (!CheckEditEmpty(editText_car_mingcheng)) {
				return false;
			}
			if (!CheckEditNumber(editText_car_jiayouliang)) {
				return false;
			}
			if (!CheckEditNumber(editText_car_jiayoufeiyong)) {
				return false;
			}
			if (PictureButton_car_jiayou!=null && !PictureButton_car_jiayou.IsExist()) {
				Utility.MessageBox( this,PictureButton_car_jiayou.FIELD );
				return false;
			}			
			if (PictureButton_car_lichengbiao!=null && !PictureButton_car_lichengbiao.IsExist()) {
				Utility.MessageBox(this, PictureButton_car_lichengbiao.FIELD );
				return false;
			}
			return true;
		}else {
			return false;
		}
	}

}
